<%
	def tableDefine=tableModel.tableDefine;
	def columns=tableDefine.columns;
	def tableNameLowerCaseFirst=tableNameUtil.lowerCaseFirst(tableDefine.id);
	def pkColumn=tableDefine.getPkColumn();
    def pkJavaType=tableNameUtil.getDataType(pkColumn?.columnType);
%>package ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.znv.common.base.BaseCrudServiceImpl;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.${tableDefine.id}Dao;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.dto.${tableDefine.id}AddDTO;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.dto.${tableDefine.id}UpdateDTO;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.dto.${tableDefine.id}ViewDTO;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.entity.${tableDefine.id}Entity;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.${tableDefine.id}Service;
import org.springframework.stereotype.Service;
import com.znv.common.utils.ConvertUtils;
import com.znv.common.utils.StringUtils;
import com.znv.common.validator.ValidatorUtils;
import com.znv.common.validator.group.AddGroup;
import com.znv.common.validator.group.UpdateGroup;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;


@Slf4j
@Service("${tableNameLowerCaseFirst}Service")
public class ${tableDefine.id}ServiceImpl extends BaseCrudServiceImpl<${tableDefine.id}Dao, ${tableDefine.id}Entity> implements ${tableDefine.id}Service {

    @Override
    public QueryWrapper<${tableDefine.id}Entity> getWrapper(Map<String, Object> params) {
		log.info("${tableDefine.cnname}-查询条件[{}]", JSONObject.toJSONString(params));
        QueryWrapper<${tableDefine.id}Entity> wrapper = new QueryWrapper<${tableDefine.id}Entity>()
<%
				columns.each{
					if(it==null || tableModel.isNotInList('searchKey',it.columnName)){
						return ;
					}
					if(tableNameUtil.getDataType(it.getColumnType()) == "String") {
						println """	.like(StringUtils.isNotEmpty(params.get("${it.dataName}")), "${it.columnName}", params.get("${it.dataName}"))""";
					}else{
						println """	.eq(StringUtils.isNotEmpty(params.get("${it.dataName}")), "${it.columnName}", params.get("${it.dataName}"))""";
					}
}%>
                .orderByDesc("created_time"); 
		return wrapper;
    }
	
	@Override
	void iSave(${tableDefine.id}AddDTO dto) {
		log.info("${tableDefine.cnname}-保存信息[{}]", JSONObject.toJSONString(dto));
		//数据校验
		ValidatorUtils.validateEntity(dto, AGroup.class);
		//数据更新
		save(ConvertUtils.sourceToTarget(dto, ${tableDefine.id}Entity.class));
	}
	
	@Override
	void iUpdate(${tableDefine.id}UpdateDTO dto) {
		log.info("${tableDefine.cnname}-更新信息[{}]", JSONObject.toJSONString(dto));
		//数据校验
		ValidatorUtils.validateEntity(dto, UpdateGroup.class);
		//数据更新
		updateById(ConvertUtils.sourceToTarget(dto, ${tableDefine.id}Entity.class));
	}
	
	@Override
	${tableDefine.id}ViewDTO iGetById(${pkJavaType} ${pkColumn.dataName}) {
		log.info("${tableDefine.cnname}-详情查询条件${pkJavaType}[{}]", ${pkColumn.dataName});
		//查询${tableDefine.cnname}详情
        ${tableDefine.id}Entity entity = getById(${pkColumn.dataName});
		return ConvertUtils.sourceToTarget(entity, ${tableDefine.id}ViewDTO.class);
	}
	
	@Override
	void eventInfoService.iDelete(${pkJavaType}[] ids) {
		log.info("${tableDefine.cnname}-删除条件[{}]", ids);
		removeByIds(ids)
	}
}